﻿using System;
using System.Collections.Generic;
using Ewk.MachineLearning.Genetic.Programming.Program;
using Ewk.MachineLearning.Genetic.Programming.Program.Functions;

namespace Ewk.MachineLearning.Genetic.Programming
{
    /// <summary>
    /// Creates <see cref="FunctionNode"/> instances.
    /// </summary>
    internal class FunctionNodeFactory
    {
        private readonly FunctionSet _functionSet;

        #region Constructor

        public FunctionNodeFactory()
        {
            _functionSet = new FunctionSet();
        }

        public FunctionNodeFactory(IEnumerable<Function> functions)
        {
            _functionSet = new FunctionSet(functions);
        }

        #endregion

        /// <summary>
        /// Creates a <see cref="FunctionNode"/> with a random function from the <see cref="FunctionSet"/>.
        /// </summary>
        /// <param name="expectedOutputTypes">The types that are expected by the consumer of the <see cref="Node"/>.</param>
        /// <returns>A <see cref="FunctionNode"/>.</returns>
        public FunctionNode CreateNode(IEnumerable<Type> expectedOutputTypes)
        {
            return new FunctionNode(_functionSet.GetRandom(expectedOutputTypes));
        }
    }
}